×
☰ See All Chapters

How to achieve synchronization in selenium WebDriver

Automation tool executes the test cases one after the other without any waits. In this case result of one test case could collide with another test case. Let us consider selenium has clicked on a button and this button invoked call to server. Before the response comes if selenium executes other test case then the result is undesirable. Synchronization in selenium web driver is a mechanism of maintaining the execution pace between automation tool (selenium web driver) and application under testing.

Implicit “WaitFor” Commands

There are number of commands which run implicitly when other commands are being executed. For example, with respect to the “clickAndWait” command, when you click on an element, the “waitForPageToLoad” command is also executed.  The implicit commands which run implicitly when other commands are being executed are listed below.

Command

Description

waitForPageToLoad

Wait until the page is fully loaded in the browser

waitForElementPresent

Wait until the specified element is present on the page

waitForElementNotPresent

Wait until the specified element is removed from the page

waitForTextPresent

Wait until the specified text is present on the page

waitForFrameToLoad

Wait until the contents of the frame are fully loaded in the browser

waitForAlertPresent

Wait until an alert window is displayed on the page

Configure default browser navigation timeout

The following statement sets the navigation timeout to 20. This means that WebDriver will wait for a maximum of 20 seconds for a page to load. If it doesn’t, then it will throw an exception.

driver.manage().timeouts().pageLoadTimeout(50,TimeUnit.SECONDS);

Selenium Implicit Wait time

Selenium Explicit Wait time

Selenium Fluent Wait

Selenium Unconditional wait

 


All Chapters
Author